package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.common.enums.EnumObtainFileWay;
import com.cw.jeeyt.service.bo.system.SystemFileTemplateBo;
import com.cw.jeeyt.dao.model.system.SystemFileTemplateDo;
import com.cw.lang.common.utils.CollectionUtil;
import com.cw.lang.common.utils.StringUtil;

/**
 * 文件模板信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemFileTemplateConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemFileTemplateBo do2Bo(SystemFileTemplateDo model) {
        if (model == null) {
            return null;
        }
        String obtainFileWayCn = StringUtil.isNotBlank(model.getObtainFileWay()) ? EnumObtainFileWay.find(
            model.getObtainFileWay())
            .getDescription() : "";
        SystemFileTemplateBo bo = new SystemFileTemplateBo();
        bo.setId(model.getId());
        bo.setTemplateCode(model.getTemplateCode());
        bo.setTemplateName(model.getTemplateName());
        // bo.setTemplateUrl(model.getTemplateUrl());
        bo.setTemplateSavePath(model.getTemplateSavePath());
        bo.setFileOutputPath(model.getFileOutputPath());
        bo.setObtainFileWayCn(obtainFileWayCn);
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemFileTemplateDo bo2Do(SystemFileTemplateBo bo) {
        if (bo == null) {
            return null;
        }
        SystemFileTemplateDo model = new SystemFileTemplateDo();
        model.setId(bo.getId());
        model.setTemplateCode(bo.getTemplateCode());
        model.setTemplateName(bo.getTemplateName());
        // model.setTemplateUrl(bo.getTemplateUrl());
        model.setTemplateSavePath(bo.getTemplateSavePath());
        model.setFileOutputPath(bo.getFileOutputPath());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemFileTemplateBo> doList2BoList(List<SystemFileTemplateDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemFileTemplateConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemFileTemplateDo> boList2DoList(List<SystemFileTemplateBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemFileTemplateConverter::bo2Do));
    }
}
